import { EVENT_NAMES } from '@/config/constant'
import mitt, { Handler } from 'mitt'

const emitter = mitt()

export function listenAdminLogout(handler: () => void) {
    console.log('开始监听用户退出')
    emitter.on(EVENT_NAMES.logout, handler as Handler)
}

export function triggerAdminLogout() {
    console.log('广播：用户退出了')
    emitter.emit(EVENT_NAMES.logout)
}

export function removeAdminLogoutListener() {
    console.log('移除用户退出监听')
    emitter.off(EVENT_NAMES.logout)
    emitter.all.delete(EVENT_NAMES.logout)
}
